package cn.clx.ymcc.web.controller;

import cn.clx.ymcc.doc.CourseDoc;
import cn.clx.ymcc.dto.CourseEsDto;
import cn.clx.ymcc.result.JSONResult;
import cn.clx.ymcc.result.PageList;
import cn.clx.ymcc.service.ISearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/search")
public class CourseController {

    @Autowired
    private ISearchService searchService;

    /**
     * ES课程搜索
     * @param dto
     * CourseDoc  存放在ES中的数据
     * @return
     */
    @RequestMapping(value="/course",method= RequestMethod.POST)
    public JSONResult search(@RequestBody CourseEsDto dto){
        PageList<CourseDoc> courseES=searchService.search(dto);
        return JSONResult.success(courseES);
    }

    /**
    * 新增ES
    */
    @RequestMapping(value="/save",method= RequestMethod.POST)
    public JSONResult saveES(@RequestBody @Valid CourseDoc doc){
        searchService.saveES(doc);
        return JSONResult.success();
    }

    /**
     * 删除ES
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    public JSONResult deleteES(@RequestParam Long id){
        searchService.deleteES(id);
        return JSONResult.success();
    }

}
